home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / fbm.uni / fbm.lha / src / clr2gray.c next >
Encoding:
C/C++ Source or Header  |  1990-06-25  |  2.9 KB  |  93 lines

  1. /*****************************************************************
  2.  * clr2gray.c: FBM Release 1.0 25-Feb-90 Michael Mauldin
  3.  *
  4.  * Copyright (C) 1989,1990 by Michael Mauldin.  Permission is granted
  5.  * to use this file in whole or in part for any purpose, educational,
  6.  * recreational or commercial, provided that this copyright notice
  7.  * is retained unchanged.  This software is available to all free of
  8.  * charge by anonymous FTP and in the UUNET archives.
  9.  *
  10.  * USAGE
  11.  *    % clr2gray [ -r<red> -g<grn> -b<blu> ] [ -<type> ] < color > gray
  12.  *
  13.  * EDITLOG
  14.  *    LastEditDate = Sun Jun 24 23:57:08 1990 - Michael Mauldin
  15.  *    LastFileName = /usr2/mlm/src/misc/fbm/clr2gray.c
  16.  *
  17.  * HISTORY
  18.  * 25-Jun-90  Michael Mauldin (mlm@cs.cmu.edu) Carnegie Mellon
  19.  *    Package for Release 1.0
  20.  *
  21.  * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  22.  *    Beta release (version 0.9) mlm@cs.cmu.edu
  23.  *
  24.  * 06-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  25.  *    Added options for RGB weights
  26.  *
  27.  *  1-Dec-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  28.  *    Created.
  29.  *****************************************************************/
  30.  
  31. # include <stdio.h>
  32. # include <math.h>
  33. # include "fbm.h"
  34.  
  35. # define USAGE \
  36. "Usage: clr2gray [ -r<red> -g<grn> -b<blu> ] [ -<type> ] < color > gray"
  37.  
  38. #ifndef lint
  39. static char *fbmid =
  40. "$FBM clr2gray.c <1.0> 25-Jun-90  (C) 1989,1990 by Michael Mauldin, source \
  41. code available free from MLM@CS.CMU.EDU and from UUNET archives$";
  42. #endif
  43.  
  44. main (argc, argv)
  45. char *argv[];
  46. { FBM input, output;
  47.   int outtype = DEF_8BIT;
  48.   int rw=0, gw=0, bw=0;
  49.  
  50.   /* Get the options */
  51.   while (--argc > 0 && (*++argv)[0] == '-')
  52.   { while (*++(*argv))
  53.     { switch (**argv)
  54.       { 
  55.     case 'r':    rw = atoi (*argv+1); SKIPARG; break;
  56.     case 'g':    gw = atoi (*argv+1); SKIPARG; break;
  57.     case 'b':    bw = atoi (*argv+1); SKIPARG; break;
  58.     case 'A':    outtype = FMT_ATK; break;
  59.     case 'B':    outtype = FMT_FACE; break;
  60.     case 'F':    outtype = FMT_FBM; break;
  61.     case 'G':    outtype = FMT_GIF; break;
  62.     case 'I':    outtype = FMT_IFF; break;
  63.     case 'L':    outtype = FMT_LEAF; break;
  64.     case 'M':    outtype = FMT_MCP; break;
  65.     case 'P':    outtype = FMT_PBM; break;
  66.     case 'R':    outtype = FMT_RLE; break;
  67.     case 'S':    outtype = FMT_SUN; break;
  68.     case 'T':    outtype = FMT_TIFF; break;
  69.     case 'X':    outtype = FMT_X11; break;
  70.     case 'Z':    outtype = FMT_PCX; break;
  71.     default:        fprintf (stderr, "%s\n", USAGE);
  72.                         exit (1);
  73.       }
  74.     }
  75.   }
  76.  
  77.   /* Use NTSC weights for defaults */
  78.   if (rw + gw + bw <= 0)
  79.   { rw = 299; gw = 587; bw = 114; }
  80.  
  81.   /* Clear the memory pointers so alloc_fbm won't be confused */
  82.   input.cm  = input.bm  = (unsigned char *) NULL;
  83.   output.cm = output.bm = (unsigned char *) NULL;
  84.  
  85.   /* Read the image and convert it, use NTSC weights */
  86.   if (read_bitmap (&input, (char *) NULL) &&
  87.       clr2gray (&input, &output, rw, gw, bw) &&
  88.       write_bitmap (&output, stdout, outtype))
  89.   { exit (0); }
  90.  
  91.   exit (1);
  92. }
  93.